using System.ComponentModel;
using NUnit.Framework;
using WB.Mvc.Forms;

namespace WB.Forms.Tests
{
	[TestFixture]
	public class ModelFieldGroupTestFixture
	{
		private ModelFieldGroup group;
		private Parent model;

		[SetUp]
		public void InitializeTest()
		{
			model = new Parent();
			group = new ModelFieldGroup();
		}

		[Test]
		public void Can_Add_Field()
		{
			group.AddField(new CharField("Test"), TypeDescriptor.GetProperties(typeof(Parent))[0]);

			Assert.AreEqual(1, group.Fields.Count);
		}

		[Test]
		public void ShouldUpdateModel()
		{
			const string updatedName = "updated-name";

			group.AddField(new CharField("Name"), TypeDescriptor.GetProperties(typeof(Parent))["Name"]);
			group.Fields[0].Value = updatedName;

			group.UpdateModel(model);

			Assert.AreEqual(model.Name, updatedName);
		}
	}
}